using SeataNet.Core.Discovery;

namespace SeataNet.Core.LoadBalance
{
    /// <summary>
    /// 负载均衡接口
    /// </summary>
    public interface ILoadBalancer
    {
        /// <summary>
        /// 从服务实例列表中选择一个实例
        /// </summary>
        /// <param name="instances">服务实例列表</param>
        /// <param name="context">上下文信息 (可用于一致性哈希等)</param>
        /// <returns>选中的服务实例，如果没有可用实例则返回null</returns>
        ServiceInstance? Select(List<ServiceInstance> instances, string? context = null);

        /// <summary>
        /// 获取负载均衡策略名称
        /// </summary>
        string GetStrategyName();
    }

    /// <summary>
    /// 负载均衡策略类型
    /// </summary>
    public enum LoadBalanceStrategy
    {
        /// <summary>
        /// 轮询
        /// </summary>
        RoundRobin,

        /// <summary>
        /// 随机
        /// </summary>
        Random,

        /// <summary>
        /// 加权轮询
        /// </summary>
        WeightedRoundRobin,

        /// <summary>
        /// 加权随机
        /// </summary>
        WeightedRandom,

        /// <summary>
        /// 一致性哈希
        /// </summary>
        ConsistentHash,

        /// <summary>
        /// 最少活跃连接
        /// </summary>
        LeastActive
    }
}
